package com.liangwj.springbootredis.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.UUID;

/**
 * <b>Description:</b> RedisUserController <br/>
 * @author Lingwenjun
 * @date 2018/12/17-11:46
 * @version 1.0
 */
@RestController
public class RedisUserController {

    @RequestMapping( value = "/uid")
    public String uid(HttpServletRequest request) {
        HttpSession session = request.getSession();
        UUID uid = (UUID) session.getAttribute("uid");

        if (uid == null) {
            uid = UUID.randomUUID();
        }
        session.setAttribute("uid", uid);
        return session.getId();
    }

}
